#不使用with语句打开f.txt文件，写入当前时间
import time
f = open('f.txt','w')
f.write(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
f.close()

import time
with open('f.txt','w') as f:
    f.write(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))